﻿#pragma once
struct KEYDEF
{
	char cNormal;	 //字符串
	char cShifted;	 //shift按下时的值
	int  cWidth;  //图标大小
	CRect rect;
	bool bHighlight;
};


#define TAB 0x02
#define CAPSLOCK 0x03
#define SHIFT 0x04
#define CTRL 0x05
#define BSPACE 0x06
#define ENTER 0x07
#define ALT 0x08
#define WINDOW 0x9
#define LEFT 0x0A
#define RIGHT 0x0B
#define UP 0x0C
#define DOWN 0x0D
#define ESC 0x0E
#define PUP 0x0F
#define PDN 0x10
#define HOME 0x11
#define END 0x12
#define INS 0x13
#define DEL 0x14
#define CLOSE 0x15
#define EMPTY 0x16

// CNumberKeyBoardDlg 对话框

class CNumberKeyBoardDlg : public CDialogEx
{
	DECLARE_DYNAMIC(CNumberKeyBoardDlg)

public:
	CNumberKeyBoardDlg(CWnd* pParent = nullptr);   // 标准构造函数
	virtual ~CNumberKeyBoardDlg();
	CString		m_strInput;
	int		m_nLeft;
	int		m_nTop;
// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_NUMKEYBOARDDLG };
#endif

private:

	CRect		m_rtArea;
	CFont	m_pFont;			//显示字体

public:
	HWND gFocus;
	int cCurrentKeyState;
	int pKeyWidth;
	int pKeyHeight;
	CTypedPtrList<CPtrList, KEYDEF*> cKeys;
	BOOL bActive;
	CFont  m_TextFont;
	CBrush m_BTBkColor[64];

private:
	void ReleaseFocus();
	void AddKey(char pNormal, char pShifted, int pWidth);
	void CalcWidthHeight();
	void DrawKey(CDC * dc, KEYDEF * key);
	void SendKey(KEYDEF * key);
	int  DescribeKeyState();
	void DrawKeyboard();
	void DoGradientFill(CDC *pDC, CRect* rect);
	void FillBkBrushColor();
	void FreeBkBrushColor();
	void DrawInBorder(CDC* pDC, CRect rt, COLORREF tc = RGB(128, 128, 128), COLORREF bc = RGB(255, 255, 255));

	// 实现
protected:
	HICON m_hIcon;
	LRESULT OnTrayNotification(WPARAM wParam, LPARAM lParam);

	// 生成的消息映射函数
	virtual BOOL OnInitDialog();
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()
public:
	virtual BOOL PreTranslateMessage(MSG* pMsg);
protected:
	virtual void PostNcDestroy();
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
public:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持
	afx_msg void OnClose();
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	// 计算按键的矩形区域
	void CalKeyRect(void);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
	afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnRButtonDblClk(UINT nFlags, CPoint point);
	afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
	afx_msg void OnDestroy();
	afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
	afx_msg void OnSetFocus(CWnd* pOldWnd);
	afx_msg BOOL OnNcActivate(BOOL bActive);
	afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message);
};
